package me.zhujin.java.learnjava.myserver.util;

/**
 * Created by zhujin on 10/20/16.
 * blog:www.zhujin.me
 * email: zhujin.nova@gmail.com
 */

import javax.script.ScriptException;
import javax.tools.JavaCompiler;
import javax.tools.ToolProvider;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;

public class JavaCompileUtil {

    static String fileToCompile = "/Users/apple/data/git/github/thenewsky/LearnJava/src/me/zhujin/java/learnjava/sxt/myserver/msp/Welcome.java";

    static {
        fileToCompile = "/Users/apple/data/git/github/thenewsky/LearnJava/res/msp/test.jsp";
    }

    private static String msp_path = System.getProperty("user.dir") + "/res/msp/";


    public static void main(String[] args) throws NoSuchMethodException, ScriptException, FileNotFoundException {
        JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
    }

    private static void test2() throws FileNotFoundException {
        JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
        // DiagnosticListener用于获取Diagnostic信息，Diagnostic信息包括：错误，警告和说明性信息
        String fullQuanlifiedFileName = fileToCompile;
        FileOutputStream err = new FileOutputStream("err.txt");
        int compilationResult = compiler.run(null, null, err, fullQuanlifiedFileName);
        if (compilationResult == 0) {
            System.out.println("Done");
        } else {
            System.out.println("Fail");
        }

    }

}